<?php

namespace addons\sum\controller\data;

use addons\sum\controller\Common;
use app\admin\model\sum\data\Richtext as RichtextModel;


class Richtext extends Common
{

    protected $noNeedLogin = ['index','preview'];
    protected $noNeedRight = ['*'];

    public function index()
    {
        $id = $this->request->param('id');

        $data = RichtextModel::where('id', $id)->find();
        if (!$data) {
            $this->error(__('No Results were found'));
        }

        $this->success('获取成功', $data);
    }

    public function preview()
    {
        $langSlug=$this->langSlug;
        $langOption=sum_config("language.option");// 语言选项
        $langDefaultSlug=$langOption[0]['slug'];// 默认语言
        $slug = $this->request->param('slug');
        $data = RichtextModel::where('slug', $slug)->where('lang',$langSlug)->find();
        if(!$data){
            //如果没有该语言的内容显示该表示第一个上传的文章
            $data = RichtextModel::where('slug', $slug)->where('lang',$langDefaultSlug)->find();
        }
        if (!$data) {
            $this->error(__('No Results were found'));
        }
        $this->success('获取成功', $data);
    }
}
